package com.network.config;

import com.network.dao.PlanDao;
import com.network.entity.Plan;
import com.network.service.PlanService;
import com.network.util.BaseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.security.access.method.P;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

@Configuration
@EnableScheduling
public class CompleteScheduleConfig implements SchedulingConfigurer {


    @Autowired
    @SuppressWarnings("all")
    PlanService planService;
    /**
     * 执行定时任务.
     */
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {

       List<Plan> plans =planService.getAll();
       for (Plan plan:plans)
       {
           BaseData.plans.put(plan.getId(),plan);

           BaseData.test.put(plan.getId(), new Runnable() {
               @Override
               public void run() {
                   System.out.println("执行定时任务: " + plan.getName());
               }
           });
       }
    }

}